package cn.schoolwow.util.test.module.query.resource.testcase;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.query.resource.QueryResource;
import cn.schoolwow.util.test.module.beanCopy.domain.UserExtend;
import cn.schoolwow.util.test.module.common.domain.User;
import org.junit.Assert;

public class GetAsInstanceTestCaseFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        {
            User user = QueryResource.newQuery("user文件", "module/query/resource/user.json")
                    .execute()
                    .getAsInstance(User.class);

            Assert.assertEquals("zhangsan", user.username);
            Assert.assertEquals("123456", user.password);
        }
        {
            UserExtend userExtend = QueryResource.newQuery("user文件", "module/query/resource/user.json")
                    .execute()
                    .getAsInstance(UserExtend.class);

            Assert.assertEquals("zhangsan", userExtend.username);
            Assert.assertEquals("123456", userExtend.password);
            Assert.assertEquals(0, userExtend.sex.intValue());
            Assert.assertEquals(20, userExtend.age.intValue());
        }
    }

    @Override
    public String name() {
        return "读取用户JSONObject并返回User对象测试用例";
    }
}
